﻿using System;
namespace Kis.Xroad.Eu {
    
    
    [System.SerializableAttribute()]
    public class SimpleUnion2 : global::Xtee.Core.Schema.XsdAnySimpleType {
        
        public SimpleUnion2(global::Xtee.Core.Schema.XsdInt value) : 
                base((System.Int32)value) {
            this.Validate();
        }
        
        public SimpleUnion2(global::Xtee.Core.Schema.XsdToken value) : 
                base((System.String)value) {
            this.Validate();
        }
        
        public SimpleUnion2(StringType0 value) : 
                base((System.String)value) {
            this.Validate();
        }
        
        public SimpleUnion2() : 
                base(string.Empty) {
        }
        
        public SimpleUnion2(string value) : 
                base((System.IComparable)Parse(value).Value) {
            this.Validate();
        }
        
        public static bool TryParse(string value, out global::Kis.Xroad.Eu.SimpleUnion2 result) {
            try {
                result = new global::Kis.Xroad.Eu.SimpleUnion2(value);
                return true;
            }
            catch (System.Exception ) {
                result = null;
                return false;
            }
        }
        
        public static global::Kis.Xroad.Eu.SimpleUnion2 Parse(string value) {
            global::Xtee.Core.Schema.XsdInt _XsdInt = null;
            if (global::Xtee.Core.Schema.XsdInt.TryParse(value,out _XsdInt)) {
                return new SimpleUnion2(_XsdInt);
            }
            global::Xtee.Core.Schema.XsdToken _XsdToken = null;
            if (global::Xtee.Core.Schema.XsdToken.TryParse(value,out _XsdToken)) {
                return new SimpleUnion2(_XsdToken);
            }
            StringType0 _StringType0 = null;
            if (StringType0.TryParse(value,out _StringType0)) {
                return new SimpleUnion2(_StringType0);
            }
             throw new FormatException("Cannot parse to type [global::Kis.Xroad.Eu.SimpleUnion2] from string value : [" + value + "]");;
        }
        
        [System.SerializableAttribute()]
        public class StringType0 : global::Xtee.Core.Schema.XsdNormalizedString {
            
            public StringType0(string value) : 
                    base(value) {
                this.Validate();
            }
            
            public StringType0() : 
                    base(string.Empty) {
            }
            
            public static bool TryParse(string value, out StringType0 result) {
                try {
                    result = new StringType0(value);
                    return true;
                }
                catch (System.Exception ) {
                    result = null;
                    return false;
                }
            }
            
            public static implicit operator String (StringType0 value) {
                return value.Value;
            }
            
            public static implicit operator StringType0 (string value) {
                if (value==null) {
                    return null;
                }
                return new StringType0(value);
            }
        }
    }
}
